<?php


class ArrayRecursiveIterator implements RecursiveIterator, Countable {

	private $data;
	private $index = 0;

	public function __construct(array $data) {
		$this->data = $data;
	}

	public function count() {
		return count($this->data);
	}

	public function valid() {
		return $this->index < $this->count();
	}

	public function current() {
		return $this->data[$this->index];
	}

	public function next() {
		$this->index++;
	}

	public function key() {
		return $this->index;
	}

	public function rewind() {
		$this->index = 0;
	}

	public function getChildren() {
		if ($this->hasChildren()) {
			return new $this($this->current());
		}
		return null;
	}

	public function hasChildren() {
		return is_array($this->current());
	}
}